package com.hfzy.ihk.web.freeswitchManage.support.base;

import com.hfzy.ihk.web.freeswitchManage.constant.RedisKeys;
import com.hfzy.ihk.web.freeswitchManage.vo.RedisData;
import lombok.extern.slf4j.Slf4j;

/**
 * czs
 * 设备控制抽象类
 */
@Slf4j
public abstract class AbstractEquipmentControlProcess {

    /**
     * 设置控制流程，更新空闲状态
     */
    public void dealChannelStatus(RedisData redisData){
        String companyAndcity = "";
        try{

            //获得队列名称
            companyAndcity = getRedisQueueCompanyAndCity(redisData);

            log.info("queueName:{}",companyAndcity+RedisKeys.SWX_CHANNEL_QUEUE);

            redisData.setQueueName(companyAndcity+RedisKeys.SWX_CHANNEL_QUEUE);

            redisData.setChannelMapName(companyAndcity+RedisKeys.SWX_CHANNEL_MAP);
            //空闲状态写队列
            putIdleChannelQueue(redisData);


        }catch (Exception e){

            log.error(">>空闲状态写入redis队列异常",e);
        }

        try{
            //同步更新附属map

            putIdleChannelMap(redisData);
        }catch (Exception e){

            log.error(">>空闲状态写入redis set 异常",e);
        }

        try{

            //更新通道状态的hash
            updateChannelSlotState(redisData);
        }catch (Exception e){

            log.error(">>空闲状态update redis 通道map异常",e);
        }

    }



    /**
     * 将空闲通道放入redis空闲队列
     */
    public abstract void putIdleChannelQueue(RedisData redisData);

    /**
     * 将空闲通道放入redis set 中，用于确保空闲通道的不会丢失
     */

    public abstract void putIdleChannelMap(RedisData redisData);


    /**
     * 更新记录通道状态的map
     */
    public abstract void updateChannelSlotState(RedisData redisData);

    public abstract String getRedisQueueCompanyAndCity(RedisData redisData);

    /**
     * 判断队列是否有丢失的idle 如果有就补回
     */
    public abstract void checkQueueIdle(RedisData redisData);
}
